﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Commctrol_HouseInfo : System.Web.UI.UserControl
{
    #region 属性
    public string AgentUrl
    {
        get
        {
            if (Request.QueryString["fyid"] == null)
                return "http://agent.house365.com/BK0985";
            return "http://agent.house365.com/BK0985?fyid=" + Request.QueryString["fyid"].ToString();
        }
    }
    public string FyId
    {
        get
        {
            if (Request.QueryString["fyid"] == null)
                return "";
            return Request.QueryString["fyid"].ToString();
        }
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        BindDingInfo();
    }

    private void BindDingInfo()
    {
        DataTable dt = getInfo(FyId);
        //这个人的房源url
        string UserUrl = " http://agent.house365.com/BK0985";

        if (dt.Rows.Count > 0)
        {
            DataRow dr = dt.Rows[0];
            string personImag = @"<a href=""{0}"" target=""_blank""><img src=""{1}"" width=""116"" height=""137""/></a>";
            string UserName = @"<a href=""{0}"" target=""_blank"">{1}</a>";

            string FyInfo1=@"<table width=""370"" border=""0"" cellspacing=""0"" cellpadding=""0"" class=""fy_tab2""><tr><td colspan=""2""><h1 class=""fy_title"">{0}</h1></td></tr><tr><td  class=""dash_line"" style="" width:215px;"" id=""selltip"">售价：<span>{1}</span> 万元 <span style=""font-size: 10px;""></span></td><td class=""dash_line"">面积：<span>{2}</span> 平方米</td></tr><tr><td class=""dash_line"">单价：{3}</td><td class=""dash_line"">户型：{4}</td></tr><tr><td class=""dash_line"">楼层：{5}</td><td class=""dash_line"">年代：{6}</td></tr><tr><td class=""dash_line"">装修：{7}</td><td class=""dash_line"">朝向：{8}</td></tr></table>";

            string FyInfo2 = @"<table width=""370"" border=""0"" cellspacing=""0"" cellpadding=""0"" class=""fy_tab3""><tr><td class=""dash_line"">小区：<a href=""http://www.house365.com/block/block_sell.php?bid=963"" target=""_blank"">{0}</a></td><td class=""dash_line"">地址：{1}</td></tr><tr><td class=""dash_line"" style=""width:220px;"">区属：<a style=""color:#924a11"" href=""http://sell.house365.com/selllist_sell.php?district=%C7%D8%BB%B4%C7%F8"" class=""search_option"" target=""_blank"">{2}</a> </td><td class=""dash_line"" style=""width:150px;"">板块：<a style=""color:#924a11"" href=""http://sell.house365.com/selllist_sell.php?district=%C7%D8%BB%B4%C7%F8&streetid=134"" target=_blank>{3}</a>&nbsp;</td></tr><tr><td class=""dash_line"">类型：<a style=""color:#924a11"" href=""http://sell.house365.com/selllist_sell.php?infotype=1"" class=""search_option"" target=""_blank"">{4}</a></td><td class=""dash_line"">权属：{5}</td></tr><tr><td class=""dash_line"">房源编号：{6}</td><td class=""dash_line"">性价比： {7}</td></tr><tr><td class=""dash_line"">更新时间：{8}</td><td class=""dash_line""></td></tr></table>";

            this.ltPersonImag.Text= string.Format(personImag,UserUrl, dr[0].ToString());
            this.ltUserName.Text = string.Format(UserName, UserUrl, dr[1].ToString());


            if (string.IsNullOrEmpty(dr["ServiceLevel"].ToString()))
            {
                for (int i = 0; i < int.Parse(dr["ServiceLevel"].ToString()); i++)
                {
                    ltUserLevel.Text += "★";
                }
                for (int i = 0; i < 5 - int.Parse(dr["ServiceLevel"].ToString()); i++)
                {
                    ltUserLevel.Text += "☆";
                }
            }

            this.LtArea.Text = dr["Area"].ToString();
            this.ltPhone.Text= this.LtCall.Text = dr["Call"].ToString();

            this.ltFyInfo.Text = string.Format(FyInfo1, dr["title"].ToString(), dr["price"].ToString(), dr["size"].ToString(), dr["onePrice"].ToString(), dr["unit"].ToString(), dr["floor"].ToString(), dr["years"].ToString(), dr["ZxHouse"].ToString(), dr["towords"].ToString());

            string strXinjiaBi = "";

            if (string.IsNullOrEmpty(dr["XinjiaBi"].ToString()))
            {
                for (int i = 0; i < int.Parse(dr["XinjiaBi"].ToString()); i++)
                {
                    strXinjiaBi += "★";
                }
                for (int i = 0; i < 5 - int.Parse(dr["XinjiaBi"].ToString()); i++)
                {
                    strXinjiaBi += "☆";
                }
            }

        this.ltInfo2.Text = string.Format(FyInfo2, dr["XqName"].ToString(),
            dr["address"].ToString(), dr["ChangJuan"].ToString(), dr["banKuai"].ToString(), dr["type"].ToString()
            , dr["right"].ToString(), dr["FyId"].ToString(),strXinjiaBi, dr["newTime"].ToString());
        }
    }






    /// <summary>
    /// 根据房源ID获取信息
    /// </summary>
    /// <param name="FyId"></param>
    /// <returns></returns>
    private DataTable getInfo(string FyId)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Imag");
        dt.Columns.Add("Name");
        dt.Columns.Add("Call");
        dt.Columns.Add("Area");
        dt.Columns.Add("company");
        dt.Columns.Add("title");
        dt.Columns.Add("price");
        dt.Columns.Add("size");
        dt.Columns.Add("onePrice");
        dt.Columns.Add("unit");

        dt.Columns.Add("floor");
        dt.Columns.Add("years");
        dt.Columns.Add("ZxHouse");
        dt.Columns.Add("towords");
        dt.Columns.Add("XqName");
        dt.Columns.Add("address");
        dt.Columns.Add("ChangJuan");
        dt.Columns.Add("banKuai");
        dt.Columns.Add("type");
        dt.Columns.Add("right");
        dt.Columns.Add("FyId");
        dt.Columns.Add("newTime");
        dt.Columns.Add("XinjiaBi");
        dt.Columns.Add("ServiceLevel");

        DataRow dr = dt.NewRow();

        dr[0] = "http://images.anjukestatic.com/attachments/10/05/07/8/c/0/1005078c05ac983050e3416d73839f67fc8420_1.jpg";
        dr[1] = "许愿望";
        dr[2] = "13916953779";
        dr[3] = "园区 坠子山";
        dr[4] = "百居益";
        dr[5] = "中华门*水榭华庭";
        dr[6] = "230";
        dr[7] = "120";
        dr[8] = "20000元/平方米";
        dr[9] = "3房2厅2卫1阳台";

        dr[10] = "2/8楼";
        dr[11] = "09年";
        dr[12] = "精装修";
        dr[13] = "南北";
        dr[14] = "苏安新村";

        dr[15] = "苏州火车站";
        dr[16] = "园区";
        dr[17] = "坠子山";

        dr[18] = "住宅";
        dr[19] = "个人";
        dr[20] = "181888";
        dr[21] = "2009-10-21 10:21:10";

        dr[22] = "高";
        dr[23] = "3";
        dt.Rows.Add(dr);

        return dt;
    }
}
